package cn.flt;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class FMTest {
	public static void main(String[] args) throws IOException, TemplateException {
		Configuration cfg = new Configuration();
		String str = FMTest.class.getClassLoader().getResource("").getFile();
		cfg.setDirectoryForTemplateLoading(new File(str));
		cfg.setObjectWrapper(new DefaultObjectWrapper());
		Template t = cfg.getTemplate("pojo.flt");
		/* 创建数据模型 */ 
        Map root = new HashMap(); 
        root.put("user", "Big Joe"); 
        Map latest = new HashMap(); 
        root.put("latestProduct", latest); 
        latest.put("url", "products/greenmouse.html"); 
        latest.put("name", "green mouse"); 
        /* 将模板和数据模型合并 */ 
        Writer out = new OutputStreamWriter(System.out); 
        t.process(root, out); 
        out.flush(); 
	}
}
